// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System.Collections.Generic;

namespace SnapObjects.Data.Informix
{
    internal class InformixSqlSelectStatementGenerator : SqlSelectStatementGenerator
    {
        private readonly string _rowNumberName = "__P_P_H_S__ROW_NUMBER__P_P_H_E__";

        public InformixSqlSelectStatementGenerator(
            ISqlStatementFactory factory,
            ISqlGenerationHelper helper,
            ITypeMapper typeMapper) : base(factory, helper, typeMapper)
        {
        }

        protected override void CreateSelectKeyword(List<SqlToken> tokens, SqlSelectStatement select)
        {
            tokens.Add(new SqlKeywordToken(SqlKeywords.SELECT));

            if (select.Skip > -1)
            {
                tokens.Add(SqlWhitespaceToken.Whitespace);
                tokens.Add(new SqlKeywordToken(InformixSqlKeywords.SKIP));
                tokens.Add(SqlWhitespaceToken.Whitespace);
                tokens.Add(new SqlNumericToken(select.Take.ToString()));
            }
            if (select.Take > -1)
            {
                tokens.Add(SqlWhitespaceToken.Whitespace);
                tokens.Add(new SqlKeywordToken(InformixSqlKeywords.FIRST));
                tokens.Add(SqlWhitespaceToken.Whitespace);
                tokens.Add(new SqlNumericToken(select.Take.ToString()));
            }
            if (select.IsDistinst)
            {
                tokens.Add(SqlWhitespaceToken.Whitespace);
                tokens.Add(new SqlKeywordToken(SqlKeywords.DISTINCT));
            }
            
            tokens.Add(SqlWhitespaceToken.Whitespace);
        }
    }
}
